package profiler.parameters;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.hyperic.sigar.Cpu;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.CpuTimer;
import org.hyperic.sigar.DiskUsage;
import org.hyperic.sigar.FileInfo;
import org.hyperic.sigar.Mem;
import org.hyperic.sigar.NetInfo;
import org.hyperic.sigar.ProcMem;
import org.hyperic.sigar.ProcStat;
import org.hyperic.sigar.ProcTime;
import org.hyperic.sigar.ProcUtil;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.Swap;
import org.hyperic.sigar.cmd.Netstat;

import profiler.parameters.monitors.CpuParameter;
import static java.lang.System.out;


public class GenericParameterMap {

	private static final String ACTUAL_DISK = "C:";
	private Map<String,GenericParameterEnum> genericMap;
	private static Object parameterToMonitor;
	static Sigar sigar = new Sigar();
	
	public GenericParameterMap(){
		createGenericMap();
		genericMap.put("00", GenericParameterEnum.CPU_PARAMETER);
		genericMap.put("01", GenericParameterEnum.CPU_INFO_PARAMETER);
		genericMap.put("02", GenericParameterEnum.CPU_TIMER_PARAMETER);
		genericMap.put("03", GenericParameterEnum.DISK_USAGE_PARAMETER);
		genericMap.put("04", GenericParameterEnum.FILE_INFO_PARAMETER);
		genericMap.put("05", GenericParameterEnum.MEM_PARAMETER);
		genericMap.put("06", GenericParameterEnum.NET_INFO_PARAMETER);
		genericMap.put("07", GenericParameterEnum.NET_STAT_PARAMETER);
		genericMap.put("08", GenericParameterEnum.PROC_STAT_PARAMETER);
		genericMap.put("09", GenericParameterEnum.PROC_MEM_PARAMETER);
		genericMap.put("10", GenericParameterEnum.PROC_TIME_PARAMETER);
		genericMap.put("11", GenericParameterEnum.PROC_UTIL_PARAMETER);
		genericMap.put("12", GenericParameterEnum.SWAP_PARAMETER);
	}

	private void createGenericMap() {
		genericMap = new HashMap<>();
	}
	
	public static String[] getParametersRequired(String monitorsRequired){
		
		return monitorsRequired.split("C");
		
	}
	
	public static List<String> generateMonitorList(String[] monitors){
		List<String> monitorList = new ArrayList<>();
		for (String parameter : monitors){
			monitorList.add(parameter);
		}
		monitorList.remove(0);
		return monitorList;
	}
	
	public static Object generateMonitor(String code) throws SigarException{
		if (!code.isEmpty()){
			
			switch (code){
			case "00":
//				parameterToMonitor = sigar.getCpu();
				parameterToMonitor = new CpuParameter();
				break;
			case "01":
				parameterToMonitor = sigar.getCpuInfoList();
				break;
			case "02":
//
				break;
			case "03":
				parameterToMonitor = sigar.getDiskUsage(ACTUAL_DISK);
				break;
			case "04":
				
				break;
			case "05":
				parameterToMonitor = sigar.getMem();
				break;
			case "06":
				parameterToMonitor = sigar.getNetInfo();
				break;
			case "07":
				parameterToMonitor = sigar.getNetStat();
				break;
			case "08":
				parameterToMonitor = sigar.getProcStat();
				break;
			case "09":
				parameterToMonitor = sigar.getMem();
				break;
			case "10":
//				parameterToMonitor = sigar.getProcTime(pid);
				break;
			case "11":
//				
				break;
			case "12":
				parameterToMonitor = sigar.getSwap();
				break;
			default:
				return null;
			}
			return parameterToMonitor;
		}
		else{
			return null;
		}
	}
	
}
